import time

from selenium.webdriver import ActionChains

from base.LoginAndQuit import TestStart
from selenium.webdriver.common.by import By


class WareHouse(object):
    def MinistryLongin(self):
        start = TestStart()
        driver = start.loadDriver()
        start.loadLogin(driver, 'http://10.10.10.120:32018/', 'administrator', "123456")
        driver.implicitly_wait(3)
        # 进入菜单
        # menu = SecondMenu
        # menu.smsReserve(driver, '//*[@id="root"]/section/section/aside[1]/div[1]/ul/li[8]/div/span/span',
        #                 '//*[@id="429$Menu"]/li[3]/div/span/span')
        # 进入菜单
        driver.find_element(By.XPATH, '//*[@id="root"]/section/section/aside/div[1]/ul/li[7]/div/span/span').click()
        driver.implicitly_wait(1)
        driver.find_element(By.XPATH, '//*[@id="429$Menu"]/li[3]/div/span/span').click()
        driver.implicitly_wait(1)
        driver.find_element(By.XPATH, '//*[@id="671$Menu"]/li[2]/div/div/div').click()

        time.sleep(5)

        # 新增按钮
        driver.find_element(By.XPATH,
                            '//*[@id="root"]/section/section/section/main/div/div/div/div[1]/div/div[2]/div[1]/div[1]/div/div/span[1]/button').click()
        time.sleep(1)
        # 添加物料
        driver.find_element(By.XPATH,
                            '/html/body/div[3]/div/div[2]/div/div[2]/div[2]/div/div/div/div/div/div/div/div[2]/div[2]/div/div/div/div[1]/div/div/button').click()
        driver.implicitly_wait(1)
        # 搜索栏
        driver.find_element(By.XPATH,
                            '/html/body/div[4]/div/div[2]/div/div[2]/div[2]/div/div/div/div/div[1]/div/div[1]/div/span/input').send_keys(
            '高分子氨')
        driver.implicitly_wait(1)
        # 选择
        driver.find_element(By.XPATH,
                            '/html/body/div[4]/div/div[2]/div/div[2]/div[2]/div/div/div/div/div[1]/div/div[3]/div/div/div/div/div[2]/div[1]/div[1]/div[1]/div[1]/div[1]/div[1]/div/div/span').click()
        driver.implicitly_wait(1)
        # 确认
        driver.find_element(By.XPATH,
                            '/html/body/div[4]/div/div[2]/div/div[2]/div[2]/div/div/div/div/div[3]/div/div[2]/button[2]').click()

        time.sleep(1)
        menu = driver.find_element_by_xpath(
            '/html/body/div[3]/div/div[2]/div/div[2]/div[2]/div/div/div/div/div/div/div/div[2]/div[2]/div/div/div/div[2]/div/div/div/div[1]/div/div/div/div/div[2]/div[1]/div[3]/div[3]/div/div/div/div/span/a')  # 定位鼠标要悬停的元素
        mouse = ActionChains(driver)
        mouse.move_to_element(menu).perform()  # 鼠标悬停到定位元素上
        time.sleep(1)
        driver.find_element(By.XPATH,
                            '/html/body/div[3]/div/div[2]/div/div[2]/div[2]/div/div/div/div/div/div/div/div[2]/div[2]/div/div/div/div[2]/div/div/div/div[2]/div/div/div/div[2]/div/div/div[2]/a').click()

        time.sleep(2)
        # 修改详细数据
        driver.find_element_by_id('ivaliday').send_keys(100)
        driver.find_element_by_id('iqtyUnloadIn').send_keys(5)
        driver.find_element_by_id('ipriceSum').send_keys(1000)
        driver.find_element_by_xpath('//*[@id="dproduct"]').click()
        time.sleep(2)
        driver.find_element_by_xpath('/html/body/div[5]/div/div/div/div/div[1]/div/input').send_keys('2022-07-29')
        time.sleep(2)
        driver.find_element_by_xpath('/html/body/div[4]/div/div[2]/div/div[2]/div[3]/button').click()
        time.sleep(1)
        # 保存
        driver.find_element_by_xpath(
            '/html/body/div[3]/div/div[2]/div/div[2]/div[2]/div/div/div/div/div/div/div/div[1]/div/div/div/div/span[2]/button').click()

        time.sleep(4)
        # 退出
        driver.find_element_by_xpath('/html/body/div[3]/div/div[2]/div/div[2]/button').click()
        time.sleep(4)

        # 修改
        driver.find_element_by_xpath(
            '//*[@id="root"]/section/section/section/main/div/div/div/div[1]/div/div[2]/div[2]/div/div/div/div/div[2]/div[1]/div[3]/div[3]/div[1]/div/div/div/span[1]/a').click()
        time.sleep(5)
        driver.find_element_by_id('snote').send_keys('这是个测试啊')
        time.sleep(1)
        # 添加物料
        driver.find_element(By.XPATH,
                            '/html/body/div[3]/div/div[2]/div/div[2]/div[2]/div/div/div/div/div/div/div/div[2]/div[2]/div/div/div/div[1]/div/div/button').click()
        time.sleep(2)
        # 搜索栏
        driver.find_element(By.XPATH,
                            '/html/body/div[5]/div/div[2]/div/div[2]/div[2]/div/div/div/div/div[1]/div/div[1]/div/span/input').send_keys(
            '高分子钛')
        time.sleep(2)
        # 选择
        driver.find_element(By.XPATH,
                            '/html/body/div[5]/div/div[2]/div/div[2]/div[2]/div/div/div/div/div[1]/div/div[3]/div/div/div/div/div[2]/div[1]/div[1]/div[1]/div[1]/div[1]/div[1]/div/div/span').click()
        driver.implicitly_wait(1)
        # 确认
        driver.find_element(By.XPATH,
                            '/html/body/div[5]/div/div[2]/div/div[2]/div[2]/div/div/div/div/div[3]/div/div[2]/button[2]').click()
        time.sleep(1)
        menu = driver.find_element_by_xpath(
            '/html/body/div[3]/div/div[2]/div/div[2]/div[2]/div/div/div/div/div/div/div/div[2]/div[2]/div/div/div/div[2]/div/div/div/div[1]/div/div/div/div/div[2]/div[1]/div[3]/div[3]/div/div/div/div/span/a')  # 定位鼠标要悬停的元素
        mouse = ActionChains(driver)
        mouse.move_to_element(menu).perform()  # 鼠标悬停到定位元素上
        time.sleep(1)
        driver.find_element(By.XPATH,
                            '/html/body/div[3]/div/div[2]/div/div[2]/div[2]/div/div/div/div/div/div/div/div[2]/div[2]/div/div/div/div[2]/div/div/div/div[2]/div/div/div/div[2]/div/div/div[2]/a').click()

        time.sleep(2)
        # 修改详细数据
        driver.find_element_by_id('ivaliday').send_keys(100)
        driver.find_element_by_id('iqtyUnloadIn').send_keys(5)
        driver.find_element_by_id('ipriceSum').send_keys(1000)
        driver.find_element_by_xpath('//*[@id="dproduct"]').click()
        time.sleep(2)
        # driver.find_element_by_xpath('/html/body/div[5]/div/div/div/div/div[1]/div/input').send_keys('2022-07-29')
        driver.find_element_by_xpath('/html/body/div[6]/div/div/div/div/div[1]/div/input').send_keys('2022-07-29')
        time.sleep(2)
        # driver.find_element_by_xpath('/html/body/div[4]/div/div[2]/div/div[2]/div[3]/button').click()
        driver.find_element_by_xpath('/html/body/div[5]/div/div[2]/div/div[2]/div[3]/button').click()
        time.sleep(3)
        # 不进行下一条修改
        # driver.find_element_by_xpath('/html/body/div[7]/div/div[2]/div/div[2]/div/div/div[2]/button[1]').click()
        driver.find_element_by_xpath('/html/body/div[8]/div/div[2]/div/div[2]/div/div/div[2]/button[1]').click()
        time.sleep(4)
        # 保存
        driver.find_element_by_xpath(
            '/html/body/div[3]/div/div[2]/div/div[2]/div[2]/div/div/div/div/div/div/div/div[1]/div/div/div/div/span[2]/button').click()
        time.sleep(4)

        # 退出
        driver.find_element_by_xpath('/html/body/div[3]/div/div[2]/div/div[2]/button').click()
        time.sleep(2)

        # 删除
        time.sleep(2)
        driver.find_element_by_xpath(
            '//*[@id="root"]/section/section/section/main/div/div/div/div[1]/div/div[2]/div[2]/div/div/div/div/div[2]/div[1]/div[3]/div[3]/div[1]/div/div/div/span[2]/a').click()
        time.sleep(1)
        driver.find_element_by_xpath('/html/body/div[6]/div/div[2]/div/div[2]/div/div/div[2]/button[2]').click()
        # driver.find_element_by_xpath('/html/body/div[4]/div/div[2]/div/div[2]/div/div/div[2]/button[2]').click()
        # time.sleep(100)

    # def MinistryAdd(self, driver):
